package edu.tongji.gridding.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils {
	public static String replaceBlank(String str) {
        String dest = "";
        if (str!=null) {
            Pattern p = Pattern.compile("\\s*|\t|\r|\n");
            Matcher m = p.matcher(str);
            dest = m.replaceAll("");
        }
        return dest;
	}
	
	public static boolean isChinese(char c) {
		int v = (int)c;
		return (v>=19968 && v<=171941);
	}
	
	public static String getNormalString(String s) {
		if(null == s || "".equals(s)) {
			return "";
		}
		return s.replaceAll("[^\u4e00-\u9fa5 a-zA-Z\t\n\r]", "");
	}
	
	public static boolean isEmpty(String str) {
		if(str == null || "".equals(str) || "null".equals(str.toLowerCase())) {
			return true;
		}
		return false;
	}
	
	public static boolean isBlank(String str) {
		if("".equals(str) || " ".equals(str) || "\t".equals(str) 
				|| "\n".equals(str) || "\r".equals(str)) {
			return true;
		}
		return false;
	}
	
	public static String array2String(String[] a) {
		int i = 0;
		StringBuilder sb = new StringBuilder();
		for(String s : a) {
			sb.append(s);
			if(i < a.length - 1) {
				sb.append("|");
			}
			++ i;
		}
		return sb.toString();
	}
}
